home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / errors.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  4KB  |  109 lines

  1. /* $Id: Errors.c,v 2.6 1992/06/23 12:33:51 grosch rel $ */
  2.  
  3. # include "Errors.h"
  4. # include "Parser.h"
  5. # include <stdio.h>
  6.  
  7. # ifdef __cplusplus
  8. extern "C" {
  9. #  include "Sets.h"
  10. }
  11. #  include <stdlib.h>
  12. # else
  13. #  include "Sets.h"
  14. #  ifdef __STDC__
  15. #   include <stdlib.h>
  16. #  else
  17.     extern void exit ();
  18. #  endif
  19. # endif
  20.  
  21. static void WriteTokenSet
  22. # if defined __STDC__ | defined __cplusplus
  23.    (FILE * yyf, tSet * yys)
  24. # else
  25.    (yyf, yys) FILE * yyf; tSet * yys;
  26. # endif
  27. {
  28.    int yyi;
  29.    for (yyi = 0; yyi <= xxMaxToken; yyi ++)
  30.       if (IsElement (yyi, yys)) (void) fprintf (yyf, "%s ", xxTokenName [yyi]);
  31. }
  32.  
  33. static void WriteErrorMessage
  34. # if defined __STDC__ | defined __cplusplus
  35.    (short yyErrorCode, short yyErrorClass, tPosition yyPosition)
  36. # else
  37.    (yyErrorCode, yyErrorClass, yyPosition) short yyErrorCode, yyErrorClass; tPosition yyPosition;
  38. # endif
  39. {
  40.    (void) fprintf (stderr, "%3d, %2d: ", yyPosition.Line, yyPosition.Column);
  41.  
  42.    switch (yyErrorClass) {
  43.    case yyFatal        : (void) fprintf (stderr, "Fatal       "); break;
  44.    case yyRestriction    : (void) fprintf (stderr, "Restriction "); break;
  45.    case yyError        : (void) fprintf (stderr, "Error       "); break;
  46.    case yyWarning    : (void) fprintf (stderr, "Warning     "); break;
  47.    case yyRepair    : (void) fprintf (stderr, "Repair      "); break;
  48.    case yyNote        : (void) fprintf (stderr, "Note        "); break;
  49.    case yyInformation    : (void) fprintf (stderr, "Information "); break;
  50.    default        : (void) fprintf (stderr, "Error class %d ", yyErrorClass);
  51.    }
  52.  
  53.    switch (yyErrorCode) {
  54.    case yyNoText    : break;
  55.    case yySyntaxError    : (void) fprintf (stderr, "syntax error"    ); break;
  56.    case yyExpectedTokens: (void) fprintf (stderr, "expected tokens"    ); break;
  57.    case yyRestartPoint    : (void) fprintf (stderr, "restart point"    ); break;
  58.    case yyTokenInserted    : (void) fprintf (stderr, "token inserted "    ); break;
  59.    default        : (void) fprintf (stderr, "error code %d", yyErrorCode);
  60.    }
  61. }
  62.  
  63. static void WriteInfo
  64. # if defined __STDC__ | defined __cplusplus
  65.    (short yyInfoClass, char * yyInfo)
  66. # else
  67.    (yyInfoClass, yyInfo) short yyInfoClass; char * yyInfo;
  68. # endif
  69. {
  70.    if (yyInfoClass == yyNone) return;
  71.    (void) fprintf (stderr, ": ");
  72.    switch (yyInfoClass) {
  73.    case yyInteger    : (void) fprintf (stderr, "%d", * (int *)    yyInfo); break;
  74.    case yyShort        : (void) fprintf (stderr, "%d", * (short *)    yyInfo); break;
  75.    case yySet        : WriteSet     (stderr, (tSet *)        yyInfo); break;
  76.    case yyToken        : (void) fprintf (stderr, "%s", xxTokenName [* (short *) yyInfo]); break;
  77.    case yyTokenSet    : WriteTokenSet  (stderr, (tSet *)        yyInfo); break;
  78.    case yyString    : (void) fprintf (stderr, "%s",            yyInfo); break;
  79.    default        : (void) fprintf (stderr, "info class: %d", yyInfoClass);
  80.    }
  81. }
  82.  
  83. void ErrorMessageI
  84. # if defined __STDC__ | defined __cplusplus
  85.    (short yyErrorCode, short yyErrorClass, tPosition yyPosition, short yyInfoClass, char * yyInfo)
  86. # else
  87.    (yyErrorCode, yyErrorClass, yyPosition, yyInfoClass, yyInfo)
  88.    short    yyErrorCode, yyErrorClass;
  89.    tPosition    yyPosition;
  90.    short    yyInfoClass;
  91.    char *    yyInfo;
  92. # endif
  93. {
  94.    WriteErrorMessage (yyErrorCode, yyErrorClass, yyPosition);
  95.    WriteInfo (yyInfoClass, yyInfo);
  96.    (void) fprintf (stderr, "\n");
  97.    if (yyErrorClass == yyFatal) exit (1);
  98. }
  99.  
  100. void ErrorMessage
  101. # if defined __STDC__ | defined __cplusplus
  102.    (short yyErrorCode, short yyErrorClass, tPosition yyPosition)
  103. # else
  104.    (yyErrorCode, yyErrorClass, yyPosition) short yyErrorCode, yyErrorClass; tPosition yyPosition;
  105. # endif
  106. {
  107.    ErrorMessageI (yyErrorCode, yyErrorClass, yyPosition, yyNone, (char *) NULL);
  108. }
  109.